﻿using System;   
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iMKelly {
    using CoreClass;
    public partial class frmReturing : Form {
        private Database dbs;
        private bool lent = false;
        public frmReturing(Database dbs) {
            InitializeComponent();
            this.dbs = dbs;
            exID.Focus();
        }

        private void UserID_TextChanged(object sender, EventArgs e) {
            User user = dbs.findUserByNoID(UserID.Text);
            if (user == null) {
                nameUser.Text = "...";
            }
            else {
                nameUser.Text = user.UserInfo.Name;
                bookID.Focus();
            }
        }

        private void bookID_TextChanged(object sender, EventArgs e) {
            BookTitle title = dbs.findBookByNoID(bookID.Text);
            if (title == null) {
                bookTitle.Text = "...";
            }
            else {
                bookTitle.Text = title.Name;
                cmdAccept.Focus();
            }
        }

        private void cmdAccept_Click(object sender, EventArgs e) {
            dbs.returnExchange(exID.Text);
            Dispose();
        }

        private void button2_Click(object sender, EventArgs e) {
            Dispose();
        }

        private void exID_TextChanged(object sender, EventArgs e) {
            String[] lst = dbs.getExchangeInfo(exID.Text);
            if (lst == null) return;

            bookID.Text = lst[0];
            UserID.Text = lst[1];
        }
    }
}
